package org.jeecg.modules.bigdatashow.service.impl;

import org.jeecg.modules.bigdatashow.entity.*;
import org.jeecg.modules.bigdatashow.mapper.ScenicMapper;
import org.jeecg.modules.bigdatashow.service.ScenicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class ScenicServiceImpl implements ScenicService {
    @Autowired
    ScenicMapper scenicMapper;

    @Override
    public PieChart findAllEmploy() {
        List<Employee> list = scenicMapper.findAllEmploy();
        PieChart pc = new PieChart();
        int nansheng = 0;
        int nvsheng = 0;
        for (int i=0;i<list.size();i++) {
            if (list.get(i).getGender() == 1) nansheng++;
            else nvsheng++;
        }
        pc.setTotalBoys(nansheng);
        pc.setTotalGirls(nvsheng);
        return pc;
    }

    @Override
    public List findDepartments() {
        List<Department> list = scenicMapper.findAllDepartment();
        List list1 = new ArrayList();
        for (int i=0;i<list.size();i++) {
            int departmentId = list.get(i).getId();
            String departmentName = list.get(i).getName();
            int departmentNumber = scenicMapper.findDepartmentNumber(departmentId);
            list1.add(departmentName);
            list1.add(departmentNumber);
        }
        return list1;
    }

    @Override
    public List findAgeType() {
        List<Employee> list = scenicMapper.findAllEmploy();
        int shaonian = 0;
        int qingnian = 0;
        int zhongnian = 0;
        int laonian = 0;
        int qita = 0;
        for (int i=0;i<list.size();i++) {
            int age = list.get(i).getAge();
            if (age<=15&&age>=12) shaonian++;
            else if (age>15&&age<=25) qingnian++;
            else if (age>25&&age<=45) zhongnian++;
            else if (age>45&&age<=60) laonian++;
            else qita++;
        }
        List list2 = new ArrayList();
        list2.add(shaonian);
        list2.add(qingnian);
        list2.add(zhongnian);
        list2.add(laonian);
        list2.add(qita);
        return list2;
    }

    @Override
    public List findAttendance() {
        List<Department> list = scenicMapper.findAllDepartment();
        List list2 = new ArrayList();
        for (int i=0;i<list.size();i++) {
            String departmentName = list.get(i).getName();
            float attendance = list.get(i).getAttendance();
            list2.add(departmentName);
            list2.add(attendance);
        }
        return list2;
    }

    @Override
    public List findWorker() {
        List<ScenicWorker> list = scenicMapper.findWorker();
        List list2 = new ArrayList();
        for (int i=0;i<list.size();i++) {
            int workerNum = list.get(i).getWorkerNum();
            list2.add(workerNum);
        }
        return list2;
    }

    @Override
    public List findTable() {
        List<Employee> list = scenicMapper.findAllEmploy();
        //1 员工总数
        int totalEmploy = list.size();
        List<Department> list2 = scenicMapper.findAllDepartment();
        //2 负责人总数
        int totalLeader = 0;
        for (int i=0;i<list2.size();i++) {
            if (list2.get(i).getEmployId() != null) totalLeader++;
        }
        //3 普通职工总数
        int totalPT = totalEmploy - totalLeader;
        List<Department2> departList = scenicMapper.findMaxDe();
        int departmentIdmax = departList.get(0).getDepartmentId();
        //4 职工数最多部门名
        String departmentName = scenicMapper.findDepartmentById(departmentIdmax);
        float maxProportion =(float)departList.get(0).getAllWorker() / (float) totalEmploy;
        //5 在员工总数中占比
        String maxPro = String.format("%.2f",maxProportion * 100) +"%";
        List<Department2> departList2 = scenicMapper.findMin();
        int departmentIdmin = departList2.get(0).getDepartmentId();
        String departmentName2 = scenicMapper.findDepartmentById(departmentIdmin);
        //6 职工数最少部门名
        float minProportion =(float)departList2.get(0).getAllWorker() / (float) totalEmploy;
        //String temp = String.format("%.2f",minProportion*100);
        //7在员工总数中占比
        String minPro = String.format("%.2f",minProportion*100) +"%";
        //8是否有设备损坏（否）
        List<LogTb> logList = scenicMapper.findLog();
        if (logList.size() == 0){
            List tableList = new ArrayList();
            tableList.add(totalEmploy);
            tableList.add(totalLeader);
            tableList.add(totalPT);
            tableList.add(departmentName);
            tableList.add(maxPro);
            tableList.add(departmentName2);
            tableList.add(minPro);
            tableList.add("否");
            tableList.add("无");
            tableList.add("无");
            tableList.add("无");
            return tableList;
        }
        //8是否有设备损坏（是）
        //9上报时间
        Date date = logList.get(0).getTime();
        //10设备所属部门
        int departmentId2 = logList.get(0).getDepartmentId();
        String departmentName10 = scenicMapper.findDepartmentById(departmentId2);
        //11部门负责人
        String leaderName = scenicMapper.findLeaderName(departmentId2);

        List tableList = new ArrayList();
        tableList.add(totalEmploy);
        tableList.add(totalLeader);
        tableList.add(totalPT);
        tableList.add(departmentName);
        tableList.add(maxPro);
        tableList.add(departmentName2);
        tableList.add(minPro);
        tableList.add("是");
        tableList.add(date);
        tableList.add(departmentName10);
        tableList.add(leaderName);
        return tableList;
    }

    @Override
    public List findPorp() {
        List list = scenicMapper.findPorp();
        return list;
    }


}
